<?php

/**
 * contact : 刘经理 19326416371
 * company : 版权所属 四川北星惯牌科技有限公司
 **/

namespace app\common\library;

use Symfony\Component\Cache\Exception\LogicException;
use think\Exception;

class LuckyCola
{
    const UID = 'FlHPvz1718767856778zeX6YzkMQv';
    const APP_KEY = 'M0qgxrYfNsillW1718767856778Rcv5rEbhaR';

    const COLA_KEY = 'M0qgxrYfNsillW1718767856778Rcv5rEbhaR';
    const API_HOST = 'https://luckycola.com.cn/';
    const TEXT_URL = 'tools/sensiWords';
    const IMAGE_URL = 'tools/checkImg';
    const USER_KEY_URL = 'ai/getColaKey';

    public function getKey()
    {
        try {
            $curl = new Curl();
            $curl->setUrl(self::API_HOST.self::USER_KEY_URL);
            $curl->post(['uid'=>self::UID,'appKey'=>self::APP_KEY]);
            return $curl->exec();
        }catch (Exception $exception){
            throw new Exception($exception->getMessage());
        }
    }

    public function textCheck($text,$isStrict=false)
    {
        try {
            $curl = new Curl();
            $curl->setUrl(self::API_HOST.self::TEXT_URL);
            $curl->post(['ColaKey'=>self::COLA_KEY,'wordStr'=>$text,'isStrict'=>$isStrict]);
            return $curl->exec();

        }catch (Exception $e){
            throw new Exception($e->getMessage());
        }
    }
}